package com.shuyun.hystrix.command;

import com.netflix.hystrix.HystrixCommand;
import com.netflix.hystrix.HystrixCommandGroupKey;
import com.netflix.hystrix.HystrixCommandKey;
import lombok.extern.slf4j.Slf4j;

/**
 * @description:
 * @author: shuai.chen@shuyun.com
 * @date: 2023/1/16 6:48 PM
 */
@Slf4j
public class CommandDynamicProp extends HystrixCommand<String> {

    private String partner;
    private String api;

    public CommandDynamicProp(String partner, String api) {
        super(Setter.withGroupKey(HystrixCommandGroupKey.Factory.asKey(partner))
                .andCommandKey(HystrixCommandKey.Factory.asKey(partner + "_" + api))
        );
        this.partner = partner;
        this.api = api;
    }

    @Override
    protected String run() throws Exception {
        log.info("访问{}合作伙伴的接口{}", partner, api);
        return "ok";
    }

    @Override
    protected String getFallback() {
        log.warn("进入降级方法");
        return "降级";
    }
}
